package
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.clearInterval;
	import flash.utils.setInterval;
	
	public class startPage extends MovieClip
	{
		var pan1 : panou1 = new panou1();
		var pan2 : panou2 = new panou2();
		var despre : detalii = new detalii();
		
		var buton1 : myButton = new myButton();
		var buton2 : myButton = new myButton();
		var buton3 : myButton = new myButton();
		var buton4 : myButton = new myButton();
		
		public function startPage()
		{
			this.addEventListener(Event.ADDED_TO_STAGE,initializare);
		}
		
		private function initializare(e:Event):void
		{
			deseneaza();
			
			plaseazaButoane();
			
			buton1.addEventListener(MouseEvent.CLICK,b1Click);
			buton2.addEventListener(MouseEvent.CLICK,b2Click);
			buton3.addEventListener(MouseEvent.CLICK,b3Click);
			buton4.addEventListener(MouseEvent.CLICK,b4Click);
		}
		
		private function b1Click(e:MouseEvent):void
		{
			pan2.visible = false;
			despre.visible = false;
			pan1.visible = true;
		}
		
		private function b2Click(e:MouseEvent):void
		{
			pan1.visible = false;
			despre.visible = false;
			pan2.visible = true;
		}
		
		private function b3Click(e:MouseEvent):void
		{
			pan1.visible = false;
			pan2.visible = false;
			despre.visible = false;
			
			deseneaza();
		}
		
		private function b4Click(e:MouseEvent):void
		{
			pan2.visible = false;
			pan1.visible = false;
			despre.visible = true;
		}
		
		private function plaseazaButoane():void
		{
			buton1.nume = "     Ecuatii";
			buton1.x = 10;
			buton1.y = 5;
			this.addChild(buton1);
			
			buton2.nume = " Trigonometrie";
			buton2.x = buton1.x+buton1.width+20;
			buton2.y = 5;
			this.addChild(buton2);
			
			buton3.nume = "  Pagina Start";
			buton3.x = buton2.x+buton2.width+20;
			buton3.y = 5;
			this.addChild(buton3);
			
			buton4.nume = "Despre Proiect";
			buton4.x = buton3.x+buton3.width+70;
			buton4.y = 5;
			this.addChild(buton4);
			
			pan1.visible = false;
			pan2.visible = false;
			despre.visible = false;
			despre.y = 30;
			this.addChild(pan1);
			this.addChild(pan2);
			this.addChild(despre);
		}
		
		private function deseneaza():void
		{
			graphics.clear();
			
			graphics.beginFill(CONST.fundalStartPage,1);
			graphics.drawRoundRect(0,0,stage.stageWidth,stage.stageHeight,10,10);
			
			genereazaForme();
		}
		
		private function genereazaForme():void
		{
			var i,n,op : int;
			var maxWidth,maxHeight,maxCuloare,maxPoz : int;
			var Width,Height,X,Y,Culoare : int;
			
			n = 30;
			maxWidth = maxHeight = 30;
			maxPoz = stage.stageWidth-100;
			maxCuloare = 1000000;
			
			for( i= 1;i <= n;i++)
			{
				op = Math.random()*2;
				
				X = 50+Math.random()*maxPoz;
				Y = 50+Math.random()*maxPoz;
				Width = 20+Math.random()*maxWidth;
				Height = 20+Math.random()*maxHeight;
				Culoare = Math.random()*maxCuloare;
				
				graphics.beginFill(Culoare,Math.random());
				
				if(op == 0)
				{
					graphics.drawRect(X,Y,Width,Height)
				}
				else
				{
					graphics.drawCircle(X,Y,Width);
				}
			}
			
		}
	}
}